package com.lianrui.app.member.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lianrui.app.member.dao.IMemberAddressDao;
import com.lianrui.app.member.domain.MemberAddress;
import com.lianrui.app.member.service.IMemberAddressService;
import com.lianrui.app.member.vos.MemberAddressPage;
import com.lianrui.commons.exception.BusinessException;
import com.lianrui.core.AbstractService;
import com.lianrui.core.IDao;


@Service("memberAddressService")
public class MemberAddressService extends AbstractService<MemberAddressPage,MemberAddress,Integer> implements IMemberAddressService {

	private static final Logger LOGGER = LoggerFactory.getLogger(MemberAddressService.class);
	
	@Autowired
	IMemberAddressDao memberAddressDao;
	
	private static final long serialVersionUID = 8680697362998246866L;

	@Override
	public IDao<MemberAddressPage, MemberAddress, Integer> getDao()
			throws BusinessException {
		return memberAddressDao;
	}

	@Override
	protected Logger getLogger() {
		return LOGGER;
	}

	public MemberAddress findDefAddr(Integer member_id) {
		return memberAddressDao.findDefAddr(member_id);
	}

	@Override
	public void setDefAddr(Integer member_id) {
		memberAddressDao.setDefAddr(member_id);
	}

	@Override
	public void cancelDefAddr(Integer addr_id, Integer member_id) {
		Map<String, Integer> map  = new HashMap<String, Integer>();
		map.put("member_id", member_id);
		map.put("addr_id", addr_id);
		
		memberAddressDao.cancelDefAddr(map);
	}
	
	public void updateToDefault(Integer addr_id, Integer member_id) {
		Map<String, Integer> map  = new HashMap<String, Integer>();
		map.put("member_id", member_id);
		map.put("addr_id", addr_id);
		memberAddressDao.setDefAddr(member_id);
		memberAddressDao.cancelDefAddr(map);
	}


	
}
